package com.keon.jianbao.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.keon.jianbao.R;
import com.keon.jianbao.ui.widget.DetailPicView;

import java.util.ArrayList;

import me.nereo.multi_image_selector.bean.Image;

/**
 * Created by keon on 15/11/19.
 */
public class GuideActivity extends Activity {
    ViewPager vpGuide;
    ArrayList<View> pageview;
    int[] images = {R.mipmap.yd1, R.mipmap.yd2, R.mipmap.yd3};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);

        vpGuide = (ViewPager) findViewById(R.id.guide_viewpager);

        initVierPager();
    }

    void initVierPager() {
        pageview = new ArrayList(3);
        for (int i = 0; i < images.length; i++) {
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(images[i]);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            if (i == 2) {
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.setClass(GuideActivity.this, MainActivity.class);
                        startActivity(intent);
                        finish();
                        overridePendingTransition(R.anim.common_out_to_left, R.anim.common_in_from_right);
                    }
                });
            }
            pageview.add(imageView);
        }

        MyPagerAdapter mPagerAdapter = new MyPagerAdapter();
        //绑定适配器
        vpGuide.setAdapter(mPagerAdapter);
        vpGuide.setCurrentItem(0);
//        vpGuide.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//                int a = 1;
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//                int a = 1;
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//                int a = 1;
//            }
//        });
    }

    class MyPagerAdapter extends PagerAdapter {
        @Override
        //获取当前窗体界面数
        public int getCount() {
            // TODO Auto-generated method stub
            return pageview.size();
        }

        @Override
        //断是否由对象生成界面
        public boolean isViewFromObject(View arg0, Object arg1) {
            // TODO Auto-generated method stub
            return arg0 == arg1;
        }
        //是从ViewGroup中移出当前View

        public void destroyItem(View arg0, int arg1, Object arg2) {
            ((ViewPager) arg0).removeView(pageview.get(arg1));
        }

        //返回一个对象，这个对象表明了PagerAdapter适配器选择哪个对象放在当前的ViewPager中
        public Object instantiateItem(View arg0, int arg1) {
            ((ViewPager) arg0).addView(pageview.get(arg1));
            return pageview.get(arg1);
        }
    }

    ;
}
